package base.stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Stream api 测试
 *
 * @author scylla
 * @version V1.0
 * @project echo-java-base
 * @title Stream测试类
 * @package base.stream
 * @since 2022/6/7 4:15 下午
 */
public class StreamDemo2 {


    public static void main(String[] args) {
        //现在需要拆分每一个单词，并去重。最终产生去重后的List
        String[] words = new String[]{"hello", "world"};

        List<String> resultList = Arrays.stream(words).flatMap(e -> Arrays.stream(e.split(""))).distinct().collect(Collectors.toList());
        System.out.println(resultList.toString());

        //现在需要将多个拆分的单词 合并成一个字符串。
        String[][] words2 = new String[][]{{"h", "e"}, {"l", "l"}, {"o", "w"}, {"o", "r"}, {"l", "d"}};
        String wordStr = Arrays.stream(words2).flatMap(Arrays::stream).collect(Collectors.joining(""));
        System.out.println(wordStr);

    }
}
